/*
 * Copyright 2011 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package com.google.gwt.testing.easygwtmock.client.internal.matchers;

import com.google.gwt.testing.easygwtmock.client.ArgumentMatcher;
import com.google.gwt.user.client.rpc.AsyncCallback;

import junit.framework.TestCase;

import java.util.HashSet;

/**
 * Tests the Any class
 * 
 * @author Michael Goderbauer
 */
public class AsyncCallbackMatcherJavaTest extends TestCase {

  private ArgumentMatcher matcher;

  @Override
  public void setUp() {
    matcher = AsyncCallbackMatcher.MATCHER;
  }
  
  public void testMatches_true() {
    assertTrue(matcher.matches(new AsyncCallbackImpl<Integer>()));
    assertTrue(matcher.matches(new AsyncCallbackImpl<String>()));
    assertTrue(matcher.matches(new AsyncCallbackImpl<Object>()));
  }
  
  public void testMatches_false() {
    assertFalse(matcher.matches(null));
    assertFalse(matcher.matches(23));
    assertFalse(matcher.matches("Hallo"));
    assertFalse(matcher.matches(new Object()));
    assertFalse(matcher.matches(new HashSet<Integer>()));
  }
  
  public void testAppend() {
    StringBuffer buffer = new StringBuffer();
    matcher.appendTo(buffer);
    assertEquals("<AsyncCallback>", buffer.toString());
  }
  
  class AsyncCallbackImpl<T> implements AsyncCallback<T> {
    @Override
    public void onFailure(Throwable arg0) {
    }
    @Override
    public void onSuccess(T arg0) {
    }
  }
}


